package com.mcflies.commons.action;

import java.util.Map;

import com.mcflies.commons.commons.ActionReturnConstantKey;

import net.sf.json.JSONObject;

/**
 * McfliesSupportAction.java
 * @describe：所有Action的基类,
 * @Copyright(c) 2012-2024 Study,mcfly
 * @author mcfly_jun
 */
public class McfliesSupportAction {
	public JSONObject retJsonObj;
	
	/**
	 * 出现异常
	 * 如果需要添加其他数据,开发人员可以使用retMap.put(key,value)添加
	 * @param retJsonObj:返回的JSON数据
	 * @param retMap：映射数据
	 * @param e:异常信息
	 */
	public void showExceptionWithJson(Map<String, Object> retMap, Exception e) {
		retMap.put(ActionReturnConstantKey.EXT_JSON_RETURN_KEY, "exception");
		retMap.put(ActionReturnConstantKey.EXCEPTION_INFO_KEY, e.getMessage());
		retJsonObj = JSONObject.fromObject(retMap);
	}
	
	/**
	 * 响应正常
	 * 如果需要添加其他数据,开发人员可以使用retMap.put(key,value)添加
	 * @param retJsonObj
	 * @param retMap
	 */
	public void showSuccessWithJson(Map<String, Object> retMap){
		retMap.put(ActionReturnConstantKey.EXT_JSON_RETURN_KEY, "true");
		retJsonObj = JSONObject.fromObject(retMap);
	}
	
	public void showFailWithJson(Map<String, Object> retMap){
		retMap.put(ActionReturnConstantKey.EXT_JSON_RETURN_KEY, "false");
		retJsonObj = JSONObject.fromObject(retMap);
	}

	public JSONObject getRetJsonObj() {
		return retJsonObj;
	}

	public void setRetJsonObj(JSONObject retJsonObj) {
		this.retJsonObj = retJsonObj;
	}

}
